import nodejs from '@dfeidao/atom-web/msg/nodejs';
import s_get from '@dfeidao/atom-web/storage/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

import set from '@dfeidao/atom-web/local/set';
import render from '@dfeidao/atom-web/render/render';
import { spaceid } from '../../atom/config';
import P01 from './P01';
import P02 from './P02';
import P04 from './P04';

export default async function a000(fd: IFeidaoAiBrowserComponent, args: {}) {

	const productid = await s_get('productid');
	set(fd, 'client_point_id', '');
	const res = await nodejs('functional-permissions/zj-000002/s001', { productid: spaceid });
	render(fd, res[0], P02, 'P02', 'replace');
	const client_type = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="client_style"]').value;
	const res_1 = await nodejs<Array<{ menu_no: string, menu_name: string, parent_no: string, _id: string }>>('functional-permissions/zj-000002/s002', { productid, client_type });

	if (res_1.length === 0) {
		render(fd, '', P01, 'P01', 'inner');
		render(fd, '', P04, 'P04', 'inner');

	} else {
		const cdata = res_1.map((d) => {
			return { id: d.menu_no, text: d.menu_name, p_id: d.parent_no, _id: d._id };
		});
		render(fd, JSON.stringify(cdata), P01, 'P01', 'inner');
	}

}
